package com.bwie.auth.controller;

import com.alibaba.fastjson.JSONObject;
import com.bwie.auth.service.AdminService;
import com.bwie.common.constants.TokenConstants;
import com.bwie.common.domain.Admin;
import com.bwie.common.domain.request.AdminRequest;
import com.bwie.common.domain.response.AdminResponse;
import com.bwie.common.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;


/**
 * @Author：作者姓名
 * @Package：com.bwie.auth.controller
 * @Project：_yk
 * @name：AdminController
 * @Date：2024/6/17 9:24
 */
@RestController
@RequestMapping("/Login")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @Autowired
    private StringRedisTemplate redisTemplate;



    @PostMapping("/toLogin")
    public Result<AdminResponse> Login(@RequestBody AdminRequest adminRequest){
        Result<AdminResponse> login = adminService.Login(adminRequest);
        return login;
    }

    @PostMapping("/info")
    public Result getInfo(){
        String token = redisTemplate.opsForValue().get(TokenConstants.LOGIN_TOKEN_KEY + "uuid");
        Admin admin = JSONObject.parseObject(token, Admin.class);
        return Result.success(admin);
    }



}
